// 引入Input模块    Output,EventEmitter模块是子组件向父组件通信用的
import { Component, OnInit,Input ,Output,EventEmitter} from '@angular/core';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {

  public searchWords:string | number | undefined
  public searchHistory:any[] = []

  //通过Output修饰器声明变量，接收 实例化EventEmitter
  @Output() private myouter = new EventEmitter

  // 使用Input修饰器绑定数据
  @Input() msg:any
  @Input() fn:any
  @Input() fcpn:any
  constructor() { }

  ngOnInit(): void {


    console.log(this.msg,'父组件传递的数据')
    // 执行父组件方法
    this.fn()
    // console.log('执行父组件方法')
    // 输出父组件
    console.log(this.fcpn,'输出父组件')
  }
  handleSearch():void{
    if(this.searchHistory.indexOf(this.searchWords) == -1 && this.searchWords != ''){
      this.searchHistory.push(this.searchWords)
    }
    
  }
  delHistory(data:any):void{
    this.searchHistory.some((item,index) => {
      if(item == data){
        this.searchHistory.splice(index,1)
        return
        // return true
      }
    })
  }
  // 给父组件传值
  doting(){
    // 广播数据
    console.log(111)
    this.myouter.emit('我是子组件传递给父组件的数据')
  }
}
